<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Sendmaillist extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->model('Findpass_m');
        $this->load->library('email');
        $this->load->model('Readcsvlogin_m');
    }
    function sendmailtoTester()
    {
        $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://smtp.gmail.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = 't06k53itjp@gmail.com';
        $config['smtp_pass']    = 'hedspit06';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'text'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      
        $this->email->initialize($config);
        $i=0;
        $source_csv=base_url().'csv_source/file.csv';
        $handle = fopen($source_csv, 'r');
        while ($array_val= fgetcsv($handle))
        {
            
            if($array_val[0]=="TestTitle")
            {
                $title=$array_val[1];
            }
            else if($array_val[0]=="TestSubTitle")
            {
                $sub_title = $array_val[1];
            }
            else if($array_val[0]=="StartDateTime")
            {
                $year = $array_val[1];
                $month = $array_val[2];
                $day = $array_val[3];
                $hour = $array_val[4];
                $minute = $array_val[5];
                $second = $array_val[6];
            }
            else if($array_val[0]=="TestTime")
            {
                $test_time = $array_val[1];
            }
            else if($array_val[0]=="Testees")
            {
                $i++;
                $testees[] = $array_val[3];
                $name[] = $array_val[4];
                $mail[] = $array_val[5];
                $id[] = $array_val[7];
                $pw[] = $array_val[9];
            }
            else if($array_val[0]=="#") break;   
        }
        fclose($handle);
        $Subject="Thong bao thi";        
        $this->email->from('t06k53itjp@gmail.com', 'K53 HEDSPI T06');
        $this->email->subject($Subject);
        for($j=0;$j<$i;$j++)
        {
            $this->email->to($mail[$j]);
            echo $mail[$j];
            $Content=$title."/n".$sub_title."/n".$year."/".$month."/".$day."-".
                    $hour.":".$minute.":".$second;
            $this->email->set_newline("\r\n");
            $this->email->message($Content);
            if($this->email->send())
            {
                echo "Send mail success";
            }
            else
                echo "Error send mail";
        }
        
    }
}
?>
